var mergeTwoLists = function (list1, list2) {
    let res = new ListNode();
    let head = res;

    while (list1 && list2) {
        if (list1.val <= list2.val) {
            res.next = list1;
            list1 = list1.next;
        } else {
            res.next = list2;
            list2 = list2.next;
        }
        res = res.next;
    }

    res.next = list1 || list2;
    return head.next;
}